package com.koron.standard.utils;

import cn.hutool.core.collection.CollUtil;
import com.koron.bean.app.AppSimpleBean;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.config.ThreadLocalContext;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author jzp
 * @since 2022/4/22
 */
public class CommonUtils {

    public static List<String> getDefaultAppids(List<String> oldAppids) {
        if (CollUtil.isEmpty(oldAppids)) {
            return Optional.ofNullable(ThreadLocalContext.get())
                    .map(EamUser::getAppSimpleBeanList)
                    .map(e -> e.stream().map(AppSimpleBean::getAppId).collect(Collectors.toList()))
                    .orElse(new ArrayList<>());
        }
        return oldAppids;
    }


    public static Integer getDefaultPublicStatus(Integer publicStatus) {
        if (publicStatus == null) {
            return 1;
        }
        return publicStatus;
    }

}
